package com.dongdongshop.txmessage;

import com.alibaba.fastjson.JSON;
import com.dongdongshop.pojo.pay.TbPayLog;
import org.apache.rocketmq.spring.core.RocketMQTemplate;
import org.springframework.messaging.Message;
import org.springframework.messaging.support.MessageBuilder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("sendTXMessage")
public class SendTXMessage {

    @Resource
    private RocketMQTemplate rocketMQTemplate;

    @RequestMapping("txMessage")
    public void txMessage(List<String> list, TbPayLog payLog) {
        //发送半消息
        String string = JSON.toJSONString(list);
        //创建message   要发送的东西
        Message message = MessageBuilder.withPayload(string).build();
        //发送事物
        // 1.事物消息发送者所在的组 //2.消息发送的topic //3.要发送的信息 //4.自己要做的事情的那些数据
        rocketMQTemplate.sendMessageInTransaction("tx-stockCount","countAndOrder",message,payLog);

       // return"send ok";
    }
}
